#include "StdAfx.h"
#include "oci.h"
#include <stdio.h>
#include <stdlib.h>
#include "ErrorCheck.h"

//check return status of each OCI calls.
//note:we should customize this function to meet our goals, like write error log or pop up a message box
//     add thread lock to make sure this function thread safe
void checkerr0(void *handle,ub4 htype,sword status)
{
	text errbuf[2048];
	CString strErrMsg;
	sb4 errcode=0;

	if (status!=OCI_SUCCESS)
	{
		ASSERT(false);
	}
	switch(status)
	{
	case OCI_SUCCESS:
		strErrMsg=_T("");
		break;

	//case OCI_SUCCESS_WITH_INFO:
	//	//todo:may be we should write information to log?
	//	//strErrMsg=_T("error-oci success with info");
	//	strErrMsg=_T("");
	//	break;

	case OCI_NEED_DATA:
		strErrMsg=_T("error-oci need data");
		break;

	case OCI_NO_DATA:
		strErrMsg=_T("error-oci no data");
		break;

	case OCI_SUCCESS_WITH_INFO:
	case OCI_ERROR:
		strErrMsg=_T("error-oci error");
		if (handle)
		{
			(void) OCIErrorGet(handle,1,(text *)NULL,&errcode,errbuf,(ub4)sizeof(errbuf),htype);
			CString strTmp;
			strTmp.Format(_T("error- %.*s"),sizeof(errbuf),errbuf);
			strErrMsg.Append(strTmp);
		}
		else
		{
			strErrMsg=_T("NULL handle.unable to extract detailed diagnostic information");
		}
		
		break;

	case OCI_INVALID_HANDLE:
		strErrMsg=_T("error-oci invalid handle");
		break;

	case OCI_STILL_EXECUTING:
		strErrMsg=_T("error-oci still executing");
		break;

	case OCI_CONTINUE:
		strErrMsg=_T("error-oci continue");
		break;

	default:
		strErrMsg=_T("error-oci default?");
		break;
	}

	if (!strErrMsg.IsEmpty())
	{
		//ReportOCIError(strErrMsg,CString(__FILE__), __LINE__, CString(__FUNCTION__));
	}
}


